<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<body>
<h2>Hello World!</h2>
<div id="main">message container</div>
</body>
<script type="text/javascript" src="static/lib/sockjs-0.3.4.min.js"></script>
<script type="text/javascript" src="static/lib/stomp.js"></script>
<script type="text/javascript" src="static/lib/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
    //连接服务器的函数
    function connect() {
        var websocket = new SockJS("http://localhost:8080/sockjs/echo");
       /* var stompClient = Stomp.over(websocket);
        stompClient.connect('', '', function (frame) {
            console.log('链接成功');
            console.log(frame)
        }, function (frame) {
            console.log('收到error消息'+frame);
        });*/
        websocket.onopen = function (evnt) {
            //console.log('链接成功');
        }
        websocket.onmessage = function (evnt) {
            //console.log('收到消息'+evnt);
            $('#main').append("<div>"+evnt+"</div>");
        };
        websocket.onerror = function (evnt) {
           // console.log('收到error消息'+evnt);
        };
        websocket.onclose = function (evnt) {
            //console.log("与服务器断开了链接!");
        }
    }
    connect();
</script>

</html>
